jun.ReturBotolDetilGrid = Ext.extend(Ext.grid.GridPanel, {
    title: "ReturBotolDetil",
    id: 'docs-jun.ReturBotolDetilGrid',
    iconCls: "silk-grid",
    viewConfig: {
        forceFit: true
    },
    sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
    columns: [
        {
            header: 'Jenis Botol',
            sortable: true,
            resizable: true,
            dataIndex: 'jenis_botol_id',
            width: 100,
            renderer:jun.renderJenisBotol
        },
        {
            header: 'JML Faktur',
            sortable: true,
            resizable: true,
            dataIndex: 'jml_faktur',
            width: 100,
            align: "right",
            renderer: Ext.util.Format.numberRenderer("0,0")
        },
        {
            header: 'JML Gudang',
            sortable: true,
            resizable: true,
            dataIndex: 'jml_data_gudang',
            width: 100,
            align: "right",
            renderer: Ext.util.Format.numberRenderer("0,0")
        },
        {
            header: 'JML Selisih',
            sortable: true,
            resizable: true,
            dataIndex: 'jml_selisih',
            width: 100,
            align: "right",
            renderer: Ext.util.Format.numberRenderer("0,0")
        }
    ],
    initComponent: function () {
        this.store = jun.rztReturBotolDetil;
        this.tbar = {
            xtype: 'toolbar',
            items: [

                {
                    xtype: 'button',
                    text: 'Ubah JML Data Gudang',
                    ref: '../btnEdit'
                }

            ]
        };
        jun.ReturBotolDetilGrid.superclass.initComponent.call(this);
        this.btnEdit.on('Click', this.loadEditForm, this);
        this.getSelectionModel().on('rowselect', this.getrow, this);
    },
    getrow: function (sm, idx, r) {
        this.record = r;
        var selectedz = this.sm.getSelections();
    },
    loadForm: function () {
        var form = new jun.ReturBotolDetilWin({modez: 0});
        form.show();
    },
    loadEditForm: function () {
        var selectedz = this.sm.getSelected();
        if (selectedz == undefined) {
            Ext.MessageBox.alert("Warning", "Anda belum memilih item");
            return;
        }
        Ext.MessageBox.prompt('Jumlah Riil', 'Masukkan jumlah data gudang:', function (btn, text) {
            if (text == "" || btn == 'cancel') return;
            var selectedz = this.sm.getSelected();
            var idz = selectedz.json.jenis_botol_id;
            var num = /^-|\d+/;
            if (num.test(text)) {
                var faktur = parseFloat(selectedz.json.jml_faktur);
                var gudang = parseFloat(text);
                var selisih = faktur - gudang;
                selectedz.set('jml_data_gudang', gudang);
                selectedz.set('jml_selisih', selisih);
                selectedz.commit();
            } else {
                Ext.MessageBox.show({
                    title: 'Error',
                    msg: 'Input harus angka.',
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.ERROR
                });
            }
        }, this);
    }
})
